<template>
  <a-modal title="选择试验计划" :visible="visible" @cancel="cancel"  width="1200px">
    <searchData :search-data="searchArr" @search="search" />
    <list-table
      ref="table"
      tableLayout="fixed"
      size="default"
      rowKey="id"
      :columns="columns"
      :request="loadData"
      :page-keys="['pageNo', 'pageSize', 'totalSize']"
      :alert="true"
      show-size-changer
      show-quick-jumper
      showPagination="auto"
      :row-selection="rowSelection"
    >
      <template slot="action" slot-scope="text, record">
        <MoreButton>
          <a @click="handleManage(0, record)" v-btnPermission="'tm_035_loo_04'">查看</a>
          <span v-btnPermission="'tm_035_edi_02'">
            <a-divider type="vertical" />
            <a @click="handleManage(1, record)">编辑</a>
          </span>
          <!-- 删除 -->
          <span v-btnPermission="'tm_035_del_03'">
            <a-divider type="vertical"></a-divider>
            <a @click="handleRemoveParams({ id: record.id })">删除</a>
          </span>
        </MoreButton>
      </template>
    </list-table>
    <div slot="footer" class="btn_box">
      <a-button type="primary" @click="cancel"> 关闭 </a-button>
      <a-button  type="primary" @click="confirmSingle"> 确定选择 </a-button>
    </div>
  </a-modal>
</template>
<script>
import { detailsQueryList } from '@/api/technical/approval'
import { listOption } from '@/api/technical/approvalPlan'
const columns = [
  { title: '施组(方案)名称', dataIndex: 'schemeName' },
  { title: '方案类型', dataIndex: 'schemeCategory' },
  { title: '计划编制人', dataIndex: 'preparedUserName' },
  { title: '计划报审时间', dataIndex: 'planReviewTime' },
  { title: '要求审批完成时间', dataIndex: 'reviewEndTime' },
  { title: '审批其他需求', dataIndex: 'reviewOtherRequirements' }
]

export default {
  props: {
    // 显隐控件
    visible: {
      type: Boolean,
      default() {
        return false
      }
    },
    typeOption: {
      type: Array,
      default() {
        return []
      }
    },
    projectId: {
      type: String,
      default() {
        return ''
      }
    },
    //是否是质量
    isQualityRoute:{
      type: Boolean,
      default() {
        return false
      }
    }
  },
  data() {
    return {
      dataList: [],
      columns,
      loadData: async (parameter) => {
        parameter.projectId = this.projectId;
        parameter.quoteStatus = 1;
        if(this.isQualityRoute){
          parameter.planType = '634286001728131072';
        }
        const requestParameters = Object.assign({}, parameter, this.queryParam)
        return detailsQueryList(requestParameters).then((res) => {
          return res
        })
      },
      selectedRowKeys: [],
      selectionRows: [],
    }
  },
  watch:{
    visible:{
          handler(newValue, oldValue){
            if(newValue){
              this.$nextTick(() => {
                this.$refs.table.refresh(true)
              })
            }
          },
          deep: true,
          immediate:true,
       }
  },
  computed: {
    searchArr() {
      let arr = [
        { name: '方案名称', type: 'input', value: 'constructionName' },
        { name: '方案类型', value: 'planType', type: 'select', data: this.typeOption },
        {
          name: '计划报审时间',
          type: 'dateRange',
          value: 'monitoringTime',
          attr: {
            rangeFormat: ['planReviewTimeBegin', 'planReviewTimeEnd']
          }
        },
        {
          name: '要求完成审批时间',
          type: 'dateRange',
          value: 'monitoringTime2',
          attr: {
            rangeFormat: ['reviewEndTimeBegin', 'reviewEndTimeEnd']
          }
        },
        { name: '计划编制人', type: 'input', value: 'preparedUserName' }
      ]
      if(this.isQualityRoute){
        arr.splice(1,1)
       }
      return arr
    },
    rowSelection() {
      return {
        type: 'radio',
        selectedRowKeys: this.selectedRowKeys,
        selectedRows: this.selectedRows, // 当前行所有数据
        onChange: this.onSelectChange,
      }
    },
  },
  methods: {
    onSelectChange(selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows[0]
    },
    cancel() {
      this.$emit('cancel', false)
    },
    listOption() {
      listOption({ type: '5' }).then((res) => {
        this.typeOption = res.data
      })
    },
    // 搜索
    search(value) {
      value && (this.queryParam = value)
      this.$refs.table.refresh(true)
    },
    //确认选中
    confirmSingle(){
      this.$emit('confirmSingle', this.selectedRows)
    }
  }
}
</script>